// YMemDC.h: interface for the YMemDC class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_YMEMDC_H__0D72554A_9CBD_4FD2_B861_F6885BBD84D4__INCLUDED_)
#define AFX_YMEMDC_H__0D72554A_9CBD_4FD2_B861_F6885BBD84D4__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "StdAfx.h"

class YMemDC : public CDC   
{
private:
	CBitmap*	m_bitmap;
	CBitmap*	m_oldBitmap;
	CDC*		m_pDC;
	CRect		m_rcBounds;
public:
	YMemDC(CDC* pDC, const CRect& rcBounds) : CDC()
	{
		CreateCompatibleDC(pDC);
		m_bitmap = new CBitmap;
		m_bitmap->CreateCompatibleBitmap(pDC, rcBounds.Width(), rcBounds.Height());
		m_oldBitmap = SelectObject(m_bitmap);
		m_pDC = pDC;
		m_rcBounds = rcBounds;
	}
	~YMemDC() 
	{
		m_pDC->BitBlt(m_rcBounds.left, m_rcBounds.top, m_rcBounds.Width(), m_rcBounds.Height(), 
			this, m_rcBounds.left, m_rcBounds.top, SRCCOPY);
		SelectObject(m_oldBitmap);
		if (m_bitmap != NULL) 
			delete m_bitmap;
	}
	YMemDC* operator->() 
	{
		return this;
	}
};

#endif // !defined(AFX_YMEMDC_H__0D72554A_9CBD_4FD2_B861_F6885BBD84D4__INCLUDED_)
